﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace FileSystemAudit
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main(params string[] args)
        {
            bool analyze = false;
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    var p = args[i];
                    if (p == "-analyze")
                        analyze = true;
                    if (p == "-roots")
                    {
                        i++;
                        for (int j = i; j < args.Length; j++)
                        {
                            p = args[j];
                            if (Directory.Exists(p))
                            {
                                FileSystemDatabaseEntities dataCtx = new FileSystemDatabaseEntities();
                                Console.WriteLine("State: " + dataCtx.Connection.State);
                                Console.WriteLine("ConnectionTimeout: " + dataCtx.Connection.ConnectionTimeout);

                                dataCtx.FolderInfos.AddObject(new FolderInfos { Uid = Guid.NewGuid(), Path = p, IsRoot = true });
                                dataCtx.SaveChanges();
                            }
                        }
                    }
                }
            }

            if (analyze)
            {
                AnalyzerManager f = new AnalyzerManager();
                var start = DateTime.Now;
                Console.WriteLine("start " + start.ToLongTimeString());
                f.Begin();
                var end = DateTime.Now;
                var dur = end.Subtract(start);

                Console.WriteLine("end  " + end.ToLongTimeString() + " operation was for " + dur.Seconds + " s & " + dur.Milliseconds + " ms");

            }

            //System.Threading.Thread.CurrentThread.Join();
            Console.WriteLine("Processing complete. Press any key to exit.");
            Console.ReadKey();


            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
    }
}
